package com.kfm.listener;

import javax.servlet.ServletContext;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import java.util.concurrent.atomic.AtomicInteger;

@WebListener
public class MyHttpSessionListener implements HttpSessionListener {

    @Override
    public void sessionCreated(HttpSessionEvent se) {
        ServletContext servletContext = se.getSession().getServletContext();

        Object numbers = servletContext.getAttribute("numbers");
        ((AtomicInteger) numbers).incrementAndGet();
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
//        Object numbers = se.getSession().getServletContext().getAttribute("numbers");
//        ((AtomicInteger) numbers).decrementAndGet();
    }
}
